/*
 * @Author: Wangtao
 * @Date: 2022-07-26 14:13:50
 * @LastEditors: Wangtao
 * @LastEditTime: 2022-08-24 18:19:49
 */
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// element-plus按需引入 start
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// element-plus按需引入 end
const path = require('path')

const array = [
  '^/api',
  '^/sms-api',
  '^/server-public',
  '^/server-crm',
  '^/server-flow',
  '^/server-work',
  '^/auth',
  '^/crm',
  '^/call',
  '^/base',
  '^/im-web',
  '^/im-center',
  '^/im-wechat',
  '^/im-robot',
  '^/download',
  '^/upload',
  '^/im-km',
  '^/im-sdk',
  '^/im-wisd',
  '^/im-report',
  '^/report',
  '^/im-third-party',
  '^/platform',
  '^/crm',
  '^/call'
] // 请求代理地址分发
var proxyObj = {}
array.forEach((item) => {
  if (item === '^/api') {
    proxyObj[item] = {
      target: 'http://mc-biz-gateway.mc-dev1.idc.7moor.com',
      ws: false,
      changeOrigin: true
    }
  } else if (item === '^/call') {
    proxyObj[item] = {
      target: 'http://call-gateway.mc-dev1.idc.7moor.com',
      ws: false,
      changeOrigin: true
    }
  } else if (item === '^/platform') {
    proxyObj[item] = {
      // target: 'http://10.1.114.21:22233',
      target: 'http://mc-biz-gateway.mc-dev1.idc.7moor.com',
      ws: true,
      changeOrigin: true
    }
  } else {
    proxyObj[item] = {
      // target: 'http://192.168.179.25:8233',
      target: 'http://mc-biz-gateway.mc-dev1.idc.7moor.com',
      ws: true,
      changeOrigin: true
    }
  }
})

export default defineConfig({
  esbuild: {
    jsxFactory: 'h',
    jsxFragment: 'Fragment'
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@app': path.resolve(__dirname, 'src/app'),
      '@common': path.resolve(__dirname, 'src/common')
    }
  },
  server: {
    host: '0.0.0.0',
    open: true,
    proxy: proxyObj,
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    hmr: true
  },
  define: {
    'process.env': {}
  }
})
